<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!--
        v-for
            - 功能：基于数据多次渲染元素或模板块渲染
            - 语法：<标签 v-for=" 取值变量 in 待循环值 "></标签>
            - 取值表达式：可直接定义临时变量；
                <div v-for="循环到的值的变量名称 in 待循环取值">
                    {{ 循环到的值的变量名称.内容 }}
                </div>
                <div v-for="(循环到的值的变量名称,循环的下标,循环计算器) in 待循环取值">
                    {{ 循环到的值的变量名称.内容 }}
                </div>
                + 待循环取值：符合插值表达式取值区域的，需要被循环的变量
                + 循环到的值的变量名称：自定义的变量名，类似于 js for……of 循环的 临时变量
                    !! 该自定义变量在 循环范围内 具有 仓库变量 变量相同的取值操作
                    !! 该变量如果和数据仓库变量名相同，循环范围内将无法加载 仓库变量

                + 循环的下标: 循环数组时对应的元素下标值 - (对象key)
                + 循环计算器: 只有在循环对象时才能定义的 一个从 0 开始的数值

            - 待循环值取值：Array | Object | number | string | Iterable (2.6 新增)
            - 取值表达式：也可以为数组索引指定别名 (或者用于对象的键)：
                <div v-for="(item, index) in items"></div>
                <div v-for="(val, key) in object"></div>
                <div v-for="(val, name, index) in object"></div>
        -->
        <ul>
            <li v-for=" city in cityList ">
                城市名称：<span style="color:red">{{ city }}</span>
            </li>
        </ul>
        <!-- {{ city }} -->
        <hr>
        <ul>
            <li v-for=" (c,i) in cityList " @click="showTip(c,index)">
                {{ i+1 }} - 城市名称：<span style="color:red">{{ c }}</span>
            </li>
        </ul>
        <hr>
        <ol>
            <li v-for=" v in user ">{{ v }}</li>
        </ol>
        <hr>
        <ol>
            <li v-for="(v,k) in user ">{{ k }}=={{ v }}</li>
        </ol>
        <hr>
        <ol>
            <li v-for="(v,k,c) in user ">{{ c }}=={{ k }}=={{ v }}</li>
        </ol>
        <hr>
        <ul>
            <li v-for=" item in citySet">{{ item }}</li>
        </ul>
        <hr>
        <ul>
            <li v-for=" (item,i) in citySet">{{ i }}=={{ item }}</li>
        </ul>
        <hr>
        <ul>
            <li v-for=" char in str ">{{ char }}</li>
        </ul>
        <hr>
        <ul>
            <li v-for=" (char,i) in str ">{{ i }}=={{ char }}</li>
        </ul>
        <hr>
        <ul>
            <li v-for=" c in 5 ">{{ c }}</li>
        </ul>
        <hr>
        <ul>
            <!-- 
                取值number表示循环多少次
                第一个变量 从 1 开始的循环计数器
                第二个变量 从 0 开始的循环计数器
             -->
            <li v-for=" (c,i) in 5 ">{{ c }}=={{ i }}</li>
        </ul>
        <hr>
        <ul>
            <li v-for=" (c,i) in citys " @click="showTipA(c.level)">
                {{ i+1 }} - 城市名称：<span style="color:red">{{ c.name }}</span>
            </li>
        </ul>
        <input type="button" value="填加城市" @click="addCity()">
        <hr>
        <ol>
            <li v-for=" itemArr in arrs">
                {{ itemArr }}
                <ul>
                    <li v-for=" item in itemArr ">{{ item }}</li>
                </ul>
            </li>
        </ol>
        <hr>
    </div>
</body>
<script>

    new Vue({
        el: "#app",
        data: {
            city: "北京",
            cityList: ["上海", "南京", "镇江", "合肥", "石家庄"],
            list: ['石家庄'],
            user: {
                name: "tom",
                age: 23
            },
            citySet: new Set(["上海", "南京", "镇江", "合肥", "石家庄"]),
            str: "abcdefg",
            citys: [
                { name: "上海", level: "低风险" },
                { name: "南京", level: "低风险" },
                { name: "镇江", level: "低风险" },
                { name: "合肥", level: "低风险" },
                { name: "石家庄", level: "高风险" }
            ],
            arrs:[
                ["aaa1","bbb1","ccc1"],
                ["aaa2","bbb2","ccc2"],
                ["aaa3","bbb3","ccc3"],
                ["aaa4","bbb4","ccc4"],
                ["aaa5","bbb5","ccc5"]
            ]
        },
        methods: {
            showTip(c) {
                console.log(c);
                if (this.list.includes(c)) {
                    alert("高风险区")
                } else {
                    alert("低风险")
                }
            },
            showTipA(level){
                alert(level)
            },
            addCity(){
                this.citys.push( { name: "合肥", level: "低风险" })
            }
        }

    })
</script>

</html>